import { createRouter, createWebHistory } from "vue-router";

import { whiteNameList } from "./constant";

import { basicRoutes } from "./routes";

const router = createRouter({
  history: createWebHistory(),
  routes: basicRoutes,
});

export function resetRouter() {
  router.getRoutes().forEach((route) => {
    const { name } = route;
    if (name && !whiteNameList.some((n) => n === name)) {
      router.hasRoute(name) && router.removeRoute(name);
    }
  });
}


export async function setupRouter(app) {
  app.use(router);
  await router.isReady();
}

export default router;